package com.yyx.app1.DiagnosticTools_function.UI.NineFunction_Activity;

import android.app.Activity;
import android.util.Log;
import android.view.WindowManager;
import android.widget.TextView;

import com.yyx.app1.CommonControls.CloudComputing_Control.CloudComputing_Control;
import com.yyx.app1.CommonControls.CloudComputing_Control.CloudComputing_Control_Adapter;
import com.yyx.app1.R;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.UiThread;
import org.androidannotations.annotations.ViewById;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by yuexing on 2015/9/11.
 */
@EActivity(R.layout.activity_commonlyusedformulas_basefunction)
public class DiagnosticTools_CommonlyUsedFormulas_SeventhFunction_Activity extends Activity{
    private String[] requres=new String[]{"正常白蛋白浓度(g/dL)","检测的白蛋白浓度(g/dL)","体重(kg)"};
    private String[] results = new String[]{"白蛋白的缺乏量(g)"};
    private String title="白蛋白的缺乏量";

    @ViewById
    CloudComputing_Control layout_base;

    @AfterViews
    public void inti()
    {
        CloudComputing_Control_Adapter adapter=new CloudComputing_Control_Adapter() {
            @Override
            public void backgroundComputing(List<HashMap<String, String>> DataList) {
                getData(DataList);
            }
        };
        layout_base.OnCreate(requres, results, title, adapter);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
    }

    @Background
    public void getData(List<HashMap<String, String>> DataList )
    {
        HashMap<String,String> map = new HashMap<>();
        for (int i = 0 ; i<DataList.size() ; ++i)
        {
            map.put(DataList.get(i).get("key"), DataList.get(i).get("value"));
        }
        setData(operation(map));
    }

    @UiThread
    public void setData(List<HashMap<String, String>> data)
    {
        if (data==null)
            return;
        TextView[] controls = layout_base.getResults();
        for (int i=0 ; i< controls.length ; ++i)
        {
            controls[i].setText(data.get(i).get("key") + ":" + data.get(i).get("value"));
        }
    }

    public List<HashMap<String, String>> operation(HashMap<String,String> map)
    {
        List<HashMap<String, String>> lmap = new ArrayList<>();
        try
        {
            double after = Double.valueOf(map.get(requres[0]));
            double before = Double.valueOf(map.get(requres[1]));
            double kg = Double.valueOf(map.get(requres[2]));
            double dog = 10*(after-before)*kg*0.3;//10 x (想要達到的白蛋白濃度g/dL –患畜目前的白蛋白濃度g/dL ) x體重( kg ) x 0.3
            HashMap<String,String> hashMap = new HashMap<>();
            hashMap.put("key",results[0]);
            hashMap.put("value",dog+"");
            lmap.add(hashMap);
            return lmap;
        }
        catch (Exception e)
        {
            Log.e("异常1509301634", e.toString());
            return null;
        }
    }
}

